home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / DragPriv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  7.8 KB  |  248 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DragPriv.cpp
  3.  
  4.     Contains:    Definition of Private classes for ODDragAndDrop.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     5/13/96    DH        1332488 - 1.0.x:User break dragging Edition
  13.                                     file into an OpenDoc window.
  14.                                     1305572 - 1.1MRD:[Cyberdog]Dragging
  15.                                     multiple items *really* slow.
  16.                                     1314704 - 1.0.x: Enourmous performance hit
  17.                                     when dragging numb erous items over
  18.                                     windows.
  19.          <3>      5/1/96    JA        1314704: Allow ODMemDragItem to use
  20.                                     pre-existing container.
  21.          <2>     3/15/96    DH        1287259 - 1.0.2 Don't get back what I put
  22.                                     in the scrapbook. Changed ODMemContainer so
  23.                                     that it has a constructor that makes a new
  24.                                     container given a container handle.
  25.          <7>      9/6/95    VL        1274572: Added GetFinderInfo and
  26.                                     GetIconFamilyFromFile.
  27.          <6>     5/25/95    jpa        List.h --> LinkList.h [1253324]
  28.          <5>    12/13/94    VL        1203627,1200603,1203451,1198037,1194537,119
  29.                                     4755,1186815: Bug fixes.
  30.          <4>     9/29/94    RA        1189812: Mods for 68K build.
  31.          <3>     9/23/94    VL        1184272: ContainerID is now a sequence of
  32.                                     octets.
  33.          <2>     7/26/94    VL        Got rid of dependency on Bento Container
  34.                                     Suite.
  35.          <1>     7/21/94    VL        first checked in
  36.  
  37.     To Do:
  38.     In Progress:
  39.         
  40. */
  41.  
  42. #ifndef _DRAGPRIV_
  43. #define _DRAGPRIV_
  44.  
  45. #ifndef _ODTYPES_
  46. #include <ODTypes.h>
  47. #endif
  48.  
  49. #ifndef _ODMEMORY_
  50. #include <ODMemory.h>
  51. #endif
  52.  
  53. #ifndef _PLFMDEF_
  54. #include <PlfmDef.h>
  55. #endif
  56.  
  57. #ifndef _LINKLIST_
  58. #include <LinkList.h>
  59. #endif
  60.  
  61. //==============================================================================
  62. // Forward declaration
  63. //==============================================================================
  64.  
  65. class    ODStorageSystem;
  66. class    ODContainer;
  67. class    ODDocument;
  68. class    ODDraft;
  69. class    PlatformFile;
  70. class    ODStorageUnit;
  71.  
  72. //==============================================================================
  73. // Constants
  74. //==============================================================================
  75.  
  76. #define kODUserPromiseFlavor    0x66696c65    // 'file'
  77. //#define kODBentoFlavor    0x626E746F    // 'bnto'
  78. // The Bento container flavor was changed to odcn so we have compatibility with
  79. // the clipboard.
  80. #define kODBentoFlavor        0x6F64636E    // 'odcn'
  81. #define kODPromiseFlavor    0x70726D73    // 'prms'
  82. #define kODPromiseDesc        0x70726D73    // 'prms'
  83. #define kODScrapTypestyl    0x7374796c    // 'styl'
  84. #define kODScrapTypestxt    0x73747874    // 'stxt'
  85. #define kODScrapTypeTEXT    0x54455854    // 'TEXT'
  86.  
  87. #define kODDropHasLeftSourceFrameMask    ~kODDropIsInSourceFrame
  88. #define kODDragHasLeftSourcePartMask    ~(kODDropIsInSourceFrame | kODDropIsInSourcePart)
  89.  
  90. // #define kODDestinationFileSpec 'dfss'
  91. // #define kODSourceFileSpec 'sfss'
  92. // #define kODPreReplaceFileEventID 'prfl'
  93. // const FourCharCode kODReplaceFileEventID = 'rfl ';
  94. // #define kODSession 'sess'
  95.  
  96. #define kODDestinationFileSpec 'DFSS'
  97. #define kODSourceFileSpec 'SFSS'
  98. #define kODReplaceFileEventID 'RFL '
  99. #define kODSession 'SESS'
  100.  
  101. const ODULong    kODInitialNumEntries = 8;
  102.  
  103. #if ODDebug
  104. // #define ODDebug_DragAndDrop 1
  105. #endif
  106.  
  107. //#define IsOpenDocDocument(osType) ((osType != 'APPL') && (osType != 'shlb'))
  108. #define SetPasteAsAttribute(self, ev, m) do {if ((m & cmdKey) && IsFrontProcess()) self->SetAttributes(ev, self->GetAttributes(ev) | kODDropIsPasteAs);} while (0)
  109.  
  110. //==============================================================================
  111. // Scalar Types
  112. //==============================================================================
  113.  
  114. typedef struct {
  115.     ODPart            *sourcePart;
  116.     ODStorageUnitView *destSUView;
  117. } ODPromiseDesc;
  118.  
  119. //==============================================================================
  120. // Function prototype
  121. //==============================================================================
  122. static ODBoolean DragItemHasFlavor(ODPlatformDragReference theDrag, ItemReference itemID, OSType    theType);
  123. static ODBoolean IsOpenDocDocument(HFSFlavor* hfsFlavor);
  124.  
  125. void GetFinderInfo(Environment* ev, ODStorageUnit* su, PlatformFile* file);
  126. void GetIconFamilyFromFile(Environment* ev, ODStorageUnit* su, PlatformFile* file);
  127.  
  128. //==============================================================================
  129. // ODDragItem
  130. //==============================================================================
  131. class ODDragItem
  132. {
  133. public:
  134.  
  135.     ODDragItem(ODStorageSystem *storage, ODBoolean IsForeignDataSU,
  136.         ODPlatformDragReference currentDrag, ItemReference currentDragItemRefNumber,
  137.         HFSFlavor* theHFSFlavor);
  138.     ODVMethod    ~ODDragItem() {}
  139.     ODNVMethod    void Initialize(Environment* ev) {}
  140.     ODVMethod    void Open(Environment* ev);
  141.     ODVMethod    void Close(Environment* ev);
  142.     ODVMethod    ODDraft* GetDraft(void) { return fDraft; }
  143.     ODVMethod    ODStorageUnit*    GetStorageUnit(Environment* ev) { return fSU; }    
  144.  
  145. protected:
  146.     void AddFinderInfoToSU( Environment* ev );
  147.     void AddMacOSTypeInfoToSU( Environment* ev );
  148.  
  149.     ODStorageUnit*                fSU;
  150.     ODPlatformDragReference     fCurrentDrag;    // A reference to the drag currently in
  151.                                                 // in progress.
  152.     ItemReference                 fCurrentDragItemRefNumber;
  153.     HFSFlavor*                    fHFSFlavorPtr;
  154.                                 // This and the reference above are
  155.                                 // used to append an HFS item to the Drag container.
  156.                                 // Apparently, this is used to allow parts to act like
  157.                                 // the Finder, and access the Finder info of items
  158.                                 // dragged into it.
  159.     ODStorageSystem*        fStorageSystem;
  160.     ODContainer*            fContainer;
  161.     ODDocument*                fDocument;
  162.     ODDraft*                fDraft;
  163. };
  164.  
  165. class ODMemDragItem : public ODDragItem
  166. {
  167. public:
  168.     ODMemDragItem(ODStorageSystem *storage, ODDraft* theDraft, ODBoolean IsForeignDataSU, 
  169.         ODPlatformDragReference currentDrag, ItemReference currentDragItemRefNumber,
  170.         HFSFlavor* theHFSFlavor) : ODDragItem(storage, IsForeignDataSU,
  171.                                   currentDrag, currentDragItemRefNumber, theHFSFlavor)
  172.         { fContainerHandle = 0; fDraft = theDraft; };
  173.                                   
  174.     ODMemDragItem( ODStorageSystem *storage, ODHandle containerH, ODBoolean IsForeignDataSU,
  175.         ODPlatformDragReference currentDrag, ItemReference currentDragItemRefNumber,
  176.         HFSFlavor* theHFSFlavor) : fContainerHandle(containerH) , 
  177.                                     ODDragItem(storage, IsForeignDataSU, currentDrag,
  178.                                     currentDragItemRefNumber, theHFSFlavor) {};
  179.     
  180.     ~ODMemDragItem();
  181.         void Initialize(Environment* ev);
  182.         void Open(Environment* ev);
  183.         void Close(Environment* ev);
  184.         ODHandle GetContainerHandle( void ) { return fContainerHandle; }
  185.         ODStorageUnit*    GetStorageUnit(Environment* ev);
  186.     
  187.     ODHandle                  fContainerHandle;
  188. };
  189.  
  190. class ODFileDragItem : public ODDragItem
  191. {
  192. public:
  193.     ODFileDragItem(ODStorageSystem *storage, ODBoolean IsForeignDataSU,
  194.         ODPlatformDragReference currentDrag, ItemReference currentDragItemRefNumber,
  195.         HFSFlavor* theHFSFlavor)
  196.         : fContainerID(0), ODDragItem(storage, IsForeignDataSU, currentDrag,
  197.         currentDragItemRefNumber, theHFSFlavor) {};
  198.        ~ODFileDragItem();
  199.     void Initialize(Environment* ev, ODContainerID* file);
  200.     ODStorageUnit*    GetStorageUnit(Environment* ev);
  201.     
  202. private:
  203.     ODContainerID*            fContainerID;
  204. };
  205.  
  206.  
  207. //==============================================================================
  208. // ODDragLink
  209. //==============================================================================
  210. class ODDragLink : public Link
  211. {
  212.     public:
  213.         ODDragLink(ODDragItem *theItem, ODBoolean cleanup);
  214.         ~ODDragLink();
  215.        
  216.         ODDragItem *fItem;
  217.         ODBoolean   fCleanup;
  218. };
  219.  
  220. //==============================================================================
  221. // Implementation
  222. //==============================================================================
  223. ODBoolean DragItemHasFlavor(ODPlatformDragReference theDrag, ItemReference itemID, OSType    theType)
  224. {
  225.     ODBoolean    result = kODFalse;
  226.     ODUShort    count;            
  227.     ODUShort    j;
  228.     OSType        itemType;
  229.  
  230.     CountDragItemFlavors(theDrag, itemID, &count);
  231.     for (j = 1; j <= count; j++)
  232.     {
  233.         OSErr err = GetFlavorType(theDrag, itemID, j, &itemType);
  234.         if ( err != noErr )
  235.             break;
  236.         if (itemType == theType)
  237.         {
  238.             result = kODTrue;
  239.             break;
  240.         }
  241.     }
  242.  
  243.     return result;
  244. }
  245.  
  246.  
  247. #endif    // _DRAGPRIV_
  248.